<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <!-- INTERFACE -->
    <cc:interface>
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <h:panelGrid columns="8">         
            <h:outputLabel value="Return Note No"/> 
            <h:outputLabel value="Purchase No"/>  
            <h:outputLabel value="Dealor Name"/>
            <h:outputLabel value="Net Total"/>
            <h:outputLabel value="Item Name"/>
            <h:outputLabel value="Item Code"/>
            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
              <pe:exporter type="xlsx" target="tblBills" fileName="pharmacy_purchase_return_detail"  />
            </p:commandButton>
            <p:commandButton value="Print" ajax="false" action="#" >
               <p:printer target="gpBill" ></p:printer>
            </p:commandButton>
            <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
            <p:inputText autocomplete="off" value="#{searchController.searchKeyword.refBillNo}"/>
            <p:inputText autocomplete="off" value="#{searchController.searchKeyword.toInstitution}"/>
            <p:inputText autocomplete="off" value="#{searchController.searchKeyword.netTotal}"/>
            <p:inputText autocomplete="off" value="#{searchController.searchKeyword.itemName}"/>
            <p:inputText autocomplete="off" value="#{searchController.searchKeyword.code}"/>
        </h:panelGrid>
        <h:panelGroup id="gpBill">
        <p:dataTable rowIndexVar="i" id="tblBills" value="#{searchController.bills}" var="bill" >
            <f:facet name="header">
                <h:outputLabel value="Purchase RETURN NOTE"/>
            </f:facet>

            <p:column headerText="Return Note No" >
                <f:facet name="header">
                    <h:outputLabel value="Return Note No" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" value="#{bill.deptId}">
                    <h:outputLabel  ></h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
            </p:column>      
            <p:column headerText="Purchase NO" >
                <f:facet name="header">
                    <h:outputLabel value="Purchase NO" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" value="#{bill.referenceBill.deptId}">
                    <h:outputLabel  ></h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
            </p:column> 
            <p:column headerText="Delaor Name" >
                <f:facet name="header">
                    <h:outputLabel value="Delaor Name" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" value="#{bill.toInstitution.name}">
                    <h:outputLabel  ></h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
            </p:column>
            <p:column headerText="Billed at"  >
                <f:facet name="header">
                    <h:outputLabel value="Billed at" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" >
                    <h:outputLabel value="#{bill.createdAt}" >
                        <f:convertDateTime pattern="dd MM yyyy hh mm a"/>
                    </h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
                <h:panelGroup rendered="#{bill.cancelled}" >
                    <h:outputLabel style="color: red;" value="Cancelled at " />
                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.createdAt}" >
                        <f:convertDateTime pattern="dd MMM yyyy hh mm a"/>
                    </h:outputLabel>
                </h:panelGroup>
                <h:panelGroup rendered="#{bill.refunded}" >
                    <h:outputLabel style="color: red;" value="Refunded at " />
                    <h:outputLabel style="color: red;" rendered="#{bill.refunded}" value="#{bill.refundedBill.createdAt}" >
                        <f:convertDateTime pattern="dd MMM yyyy hh mm a"/>
                    </h:outputLabel>
                </h:panelGroup>
            </p:column>                 
            <p:column headerText="Billed by" >
                <f:facet name="header">
                    <h:outputLabel value="Billed by" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" >
                    <h:outputLabel value="#{bill.creater.webUserPerson.name}" >                                      
                    </h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
                <h:panelGroup rendered="#{bill.cancelled}" >
                    <h:outputLabel style="color: red;" value="Cancelled By " />
                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.creater.webUserPerson.name}" >                                       
                    </h:outputLabel>
                </h:panelGroup>
                <h:panelGroup rendered="#{bill.refunded}" >
                    <h:outputLabel style="color: red;" value="Refunded By " />
                    <h:outputLabel style="color: red;" rendered="#{bill.refunded}" value="#{bill.refundedBill.creater.webUserPerson.name}" >

                    </h:outputLabel>
                </h:panelGroup>
            </p:column>          
            <p:column headerText="Paymentmethod"  >
                <f:facet name="header">
                    <h:outputLabel value="Paymentmethod" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" >
                    <h:outputLabel value="#{bill.paymentMethod}" ></h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
            </p:column>                               
            <p:column headerText="Net Value" style="text-align: right;"  >
                <f:facet name="header">
                    <h:outputLabel value="Net Value" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" >
                    <h:outputLabel value="#{bill.netTotal}" >
                        <f:convertNumber pattern="#,##0.00"/>
                    </h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
            </p:column>
            
            <p:column headerText="Sale Value" style="text-align: right;"  >
                <f:facet name="header">
                    <h:outputLabel value="Sale Value" />
                </f:facet>
                <h:commandLink action="pharmacy_reprint_purchase_return" >
                    <h:outputLabel value="#{bill.saleValue}" >
                        <f:convertNumber pattern="#,##0.00"/>
                    </h:outputLabel>
                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                </h:commandLink>
            </p:column>
            
            <p:column headerText="Comments" >
                <f:facet name="header">
                    <h:outputLabel value="Comments" />
                </f:facet>
                <h:outputLabel rendered="#{bill.refundedBill ne null}" value="#{bill.refundedBill.comments}" >
                </h:outputLabel>
                <h:outputLabel  rendered="#{bill.cancelledBill ne null}" value="#{bill.cancelledBill.comments}" >
                </h:outputLabel>
            </p:column>
        </p:dataTable>
        </h:panelGroup>
    </cc:implementation>
</html>